﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using Frame.Lib.Core.Base;

namespace Jzy.Workflow.Line
{
    public class FlowLineDAL : BaseDAL
    {
        internal List<FlowLineInfo> GetList(int flowID)
        {
            string sql = "select * from " + WFTableName.FlowLine + " where FlowID = @p0";
            List<FlowLineInfo> list = dbOper.Query<FlowLineInfo>(sql, flowID);
            return list;
        }

        internal void DeleteByNodeID(object nodeID)
        {
            string sql = "delete from " + WFTableName.FlowLine + " where FromNodeID = " + nodeID + " or ToNodeID = " + nodeID;

            dbOper.RunSql(sql);
        }

        internal bool Exist(int fromNodeID,int toNodeID, object id)
        {
            string sql = "select count(*) from " + WFTableName.FlowLine + " where FromNodeID = @p0 and ToNodeID = @p1";
            List<int> count = null;
            if (id == null)
            {
                count = dbOper.Query<int>(sql, fromNodeID, toNodeID);
            }
            else
            {
                sql += " and ID != @p2";
                count = dbOper.Query<int>(sql, fromNodeID, toNodeID, id);
            }
            bool flag = (count.First() > 0) ? true : false;
            return flag;

        }
    }

}
